<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

    <script>

        const arr1 = [1, [2, 3], [4, [5]]];

        // 一维数组的深拷贝

        // 遍历  push

        // concat

        // slice

        // ...

        // const arr2 = [...arr1];

        // arr1[1].push(6);

        // console.log(arr2);


        // const arr1 = [1, [2, 3], [4, [5]]];

        function deepCopy(arr) {
            const arr2 = [];
            for (let i = 0; i < arr.length; i++) {
                // 判断是不是数组
                if (Array.isArray(arr[i])) {
                    // 需要把 arr[i] 进行深拷贝  
                    // const arr3 = deepCopy(arr[i]);
                    // arr2.push(arr3);
                    arr2.push(deepCopy(arr[i]));
                }
                else {
                    arr2.push(arr[i]);
                }
            }

            return arr2
        }

        const arr2 = deepCopy(arr1);

        arr1[1].push(6);

        console.log(arr2);



        {
            console.log(a);
            let a = 1;
            console.log(a);
        }







    </script>

</body>

</html>